package com.uwang.library.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.uwang.library.dao.MemberListDao;
import com.uwang.library.model.MemberListModel;
import com.uwang.library.util.DruidUtil;

public class MemberListDaoImpl implements MemberListDao{

	@Override
	public List<MemberListModel> getAllMember() {
		PreparedStatement preparedStatement;
		ResultSet resultSet = null;
		List<MemberListModel> memberList = new ArrayList<>();
			
		try {
			Connection connection= DruidUtil.getConnection();
			String sql = "select id,user_name userName,sex,user_phone userPhone,email,enclosure,address,beizhu,create_time createTime from member";
			preparedStatement = connection.prepareStatement(sql);
			resultSet = preparedStatement.executeQuery();
			while (resultSet.next()) {
				MemberListModel memberListModel = new MemberListModel();
				memberListModel.setId(resultSet.getInt("id"));
				memberListModel.setUserName(resultSet.getString("userName"));
				memberListModel.setSex(resultSet.getString("sex"));
				memberListModel.setUserPhone(resultSet.getString("userPhone"));
				memberListModel.setEmail(resultSet.getString("email"));
				memberListModel.setEnclosure(resultSet.getString("enclosure"));
				memberListModel.setAddress(resultSet.getString("address"));
				memberListModel.setBeizhu(resultSet.getString("beizhu"));
				memberListModel.setCreateTime(resultSet.getDate("createTime"));
				memberList.add(memberListModel); 
				} 
			}catch(SQLException e) {
				e.printStackTrace();
			}
		return memberList;
	}


}
